﻿#include "frmcontrol.h"
#include "ui_frmcontrol.h"
#include <qtextcodec.h>

FrmControl::FrmControl(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FrmControl)
{
    ui->setupUi(this);
    manager = new QNetworkAccessManager(this);  //新建QNetworkAccessManager对象
    connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(replyFinished(QNetworkReply*)));//关联信号和槽
}

FrmControl::~FrmControl()
{
    delete ui;
}

void FrmControl::replyFinished(QNetworkReply *reply)
{
    QString allinfo = reply->readAll();
    qDebug()<<"["<<__FILE__<<"]"<<__LINE__<<__FUNCTION__<<" "<<allinfo;
    ui->textShow->setText(allinfo);
}

void FrmControl::on_btnHello_clicked()
{
    QString strUrl = ui->lineHello->text();
    QNetworkRequest quest;
//    char quest_array[256]="http://localhost:8090/hello";
//    quest.setUrl(QUrl(quest_array));
    quest.setUrl(QUrl(strUrl));
    quest.setHeader(QNetworkRequest::UserAgentHeader,"RT-Thread ART");
    /*发送get网络请求*/
    manager->get(quest);
}

void FrmControl::on_btnList_clicked()
{
    QString strUrl = ui->lineList->text();
    QNetworkRequest quest;
    quest.setUrl(QUrl(strUrl));
    quest.setHeader(QNetworkRequest::UserAgentHeader,"RT-Thread ART");
    /*发送get网络请求*/
    manager->get(quest);
}

void FrmControl::on_btnJson_clicked()
{
    QString strUrl = ui->lineJson->text();
    QNetworkRequest quest;
    quest.setUrl(QUrl(strUrl));
    quest.setHeader(QNetworkRequest::UserAgentHeader,"RT-Thread Json");
    /*发送get网络请求*/
    manager->get(quest);
}
